package no.uials.distsys;

/**
 *
 * @author Anders
 */
public class OrderLine implements java.io.Serializable {
    private Article article;
    private int units;

    /**
     * Makes a new OrderLine.
     * 
     * @param article the article of the OrderLine.
     * @param units the number of units in the OrderLine.
     */
    public OrderLine(Article article, int units) {
        this.article = article;
        this.units = units;
    }

    /**
     * Returns the Article in the OrderLine.
     * 
     * @return the Article.
     */
    public Article getArticle() {
        return article;
    }

    /**
     * Returns the number of units in the OrderLine.
     * 
     * @return the number of units.
     */
    public int getUnits() {
        return units;
    }
    
    /**
     * Sets the number of units in the OrderLine to the given number.
     * 
     * @param units the given number.
     * @return the new number of units in the OrderLine.
     */
    public int setUnits(int units) {
        return this.units = units;
    }

    /**
     * Adds the given number to the number of units in the OrderLine.
     * 
     * @param units the number of units to add to the current number.
     * @return the new number of units in the OrderLine.
     */
    public int addUnits(int units) {
        if ((this.units + units) < 0) {
            return units = 0;
        } else {
            return this.units += units;
        }
    }
    
    /**
     * Returns the total price for the OrderLine.
     * 
     * @return the total price.
     */
    public Double getTotal() {
        return units * article.getPrice();
    }
}